﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Core.Mapping;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration;
using WJ.Infrastructure.DDD;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Reflection;


namespace WJ.Infrastructure.EF
{
    public class EFContext : DbContext, IDisposable, IUnitOfWork
    {
        public EFContext()
            : base("DBConn")
        {
            this.Configuration.LazyLoadingEnabled = true;
            this.Configuration.ProxyCreationEnabled = true;
        }

        static EFContext()
        {
            Database.SetInitializer<EFContext>(null);
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {

            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

        }

        public int Commit()
        {

            try
            {
                int dbres = this.SaveChanges();

                return 1;
            }
            catch (Exception e)
            {
                Log.Log.Error(e);
                return 0;
            }
 
        }

        public void CommitAndRefreshChanges()
        {
            throw new NotImplementedException();
        }

        public void RollbackChanges()
        {
            throw new NotImplementedException();
        }


        public void BeginChanges()
        {
            throw new NotImplementedException();
        }


    }
}
